# -*- coding:utf-8 -*-
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

from base.base import Base
from handle.handle_log import log
from pages.login import Login
from handle.handle_yaml import attendance_manage_yaml_handle
from handle.handle_csv import handleAttendanceManageData
from config.constant import (
    VOCATION_DATE_DAY,
    VOCATION_DATE_HARF_DAY,
    VOCATION_WORK_DAY
)


class Vocation(Base):
    """
    假期
    """
    def __init__(self, driver, url):
        """
        初始化
        :param driver: 驱动
        :param url: 页面链接url
        """
        super().__init__(driver=driver)
        self.driver = driver
        self.url = url

        """ 登录 """
        lg = Login(self.driver, self.url)
        lg.login()

    def add_vocation(self, lis, case_num):
        """
         添加假期类型
        :return:
        """
        """ 引入页面元素 """
        ele = attendance_manage_yaml_handle()

        """ 打开假期页面 """
        self.driver.get(ele["attendance"]["attendance_page_url"])

        """ 点击假期类型 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["add_page"]
        ).click()
        log.debug("--进入假期页面---")

        """ 点击添加假期 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["add_vocation"]
        ).click()
        log.debug("---点击添加假期类型---")

        """ 输入假期名称 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["input_name"]
        ).send_keys(lis[case_num][1])
        log.debug("---输入假期名称---")

        """ 输入排序 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["input_sort"]
        ).send_keys(lis[case_num][2])
        log.debug("---输入排序---")

        """ 点击启用状态 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["open_statusUp"]
        ).click()
        log.debug("---点击启用状态---")

        """ 选择最小请假天数 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["vocation_days"]
        ).click()
        if VOCATION_DATE_DAY == lis[case_num][3]:
            self.find_element(
                By.CSS_SELECTOR,
                ele["attendance"]["add_vocation_case"]["select_time_day"]
            ).click()
        elif VOCATION_DATE_HARF_DAY == lis[case_num][3]:
            self.find_element(
                By.CSS_SELECTOR,
                ele["attendance"]["add_vocation_case"]["select_time_harf_day"]
            ).click()
        else:
            self.find_element(
                By.CSS_SELECTOR,
                ele["attendance"]["add_vocation_case"]["select_time_h"]
            ).click()

        log.debug("---选择最小请教天数--")

        """ 请教时长核算 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["compute_vocation"]
        ).click()
        if VOCATION_WORK_DAY in lis[case_num][4]:
            self.find_element(
                By.CSS_SELECTOR,
                ele["attendance"]["add_vocation_case"]["select_day"]
            ).click()
        else:
            self.find_element(
                By.CSS_SELECTOR,
                ele["attendance"]["add_vocation_case"]["select_nature_day"]
            ).click()
        log.debug("---选择请假时长核算--")

        """ 点击确定 """
        self.find_element(
            By.XPATH,
            ele["attendance"]["add_vocation_case"]["confirm"]
        ).click()
        log.debug("---点击确定---")

        """验证添加"""
        self.find_element(
            By.XPATH,
            ele["attendance"]["check_add"]["search_vocation"]
        ).send_keys(lis[case_num][1])
        log.debug("---输入名称进行搜索验证---")
        self.find_element(
            By.XPATH,
            ele["attendance"]["check_add"]["click_search"]
        ).click()
        log.debug("---点击搜索---")

        text_name = self.find_element(
            By.XPATH,
            ele["attendance"]["check_add"]["check_name"]
        ).text
        log.debug("---获取名称---")
        text_status = self.find_element(
            By.XPATH,
            ele["attendance"]["check_add"]["check_status"]
        ).text
        log.debug("---获取状态---")

        return text_name, text_status

    def edit_vocation(self, lis, case_num):
        """
        编辑假期用列
        :param lis:
        :param case_num:
        :return:
        """
        log.debug("---编辑假期---")
        ele = attendance_manage_yaml_handle()
        """ 打开假期页面 """
        self.driver.get(ele["attendance"]["attendance_page_url"])
        log.debug("---打开假期页面---")
        """ 搜索假期 """
        """验证添加"""
        self.find_element(
            By.XPATH,
            ele["attendance"]["check_add"]["search_vocation"]
        ).send_keys(lis[case_num][1])
        log.debug("---输入名称进行搜索验证---")
        pass

    def delete_vacation(self, lis, case_num):
        """
        删除假期
        :param lis:
        :param case_num:
        :return:
        """
        pass


class Classes(Base):
    """
    班次管理
    """
    def __init__(self, driver, url):
        """
        初始化
        :param driver: 驱动
        :param url: 页面链接url
        """
        super().__init__(driver=driver)
        self.driver = driver
        self.url = url

        """ 登录 """
        lg = Login(self.driver, self.url)
        lg.login()

    def add_classes(self, lis, case_num):
        """
        添加班次
        :param lis:
        :param case_num:
        :return:
        """
        pass



class AttendanceGrouping(Base):
    """
    考勤分组
    """
    def __init__(self, driver, url):
        """
        初始化
        :param driver: 驱动
        :param url: 页面链接url
        """
        super().__init__(driver=driver)
        self.driver = driver
        self.url = url

        """ 登录 """
        lg = Login(self.driver, self.url)
        lg.login()

    # def








if __name__ == "__main__":
    driver = webdriver.Chrome()
    url = "http://ecp.gzctdi-test.com/tenement/"
    att = Vocation(driver, url)
    data = handleAttendanceManageData()
    txt_name, txt_status = att.add_vocation(data, 0)
    print(txt_status, txt_name)
    time.sleep(3)
    driver.quit()







